<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组的遍历</title>
    <script>
        const str1 = '赵云,关羽,张飞,黄忠,马超'
        const str2 = 'hello world!'

        arr1 = str1.split(',')
        console.log(arr1)

        for (let i in arr1) {
            console.log(arr1[i])
        }

        arr2 = str2.split('')
        for (let i of arr2) {
            console.log(i)
        }


        // 练习 :定义一个Person类，类里有两个属性，name和age,然后创建几个对象，将其添加到数组中，要求遍历数组，并打印未成年人信息

        class Person {
            constructor(name, age) {
                this.name = name
                this.age = age
            }
        }
        const personArr = [
            new Person('小李', 27),
            new Person('小龙', 27),
            new Person('朱丽叶', 2),
            new Person('罗密欧', 5),
        ]
        const fn = (obj,a) => {
            new_obj=[]
            for (let i of obj) {
                if (a(i)) {
                    new_obj.push(i)
                }
            }
            return new_obj
        }
        console.log(fn(personArr,a  =>a.age<18))
        const  arr=[0,1,2,3,4,5,6,7,8,9]
        result=fn(arr,a =>a%2==0)
        console.log(result)
    </script>
    </script>
</head>

<body>

</body>

</html>